﻿using mars_client.csharp;
using mars_client.csharp.enums;
using mars_client.csharp.model;
using mars_client.csharp.radar;
using mars_client.gui.window;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace mars_client.gui.page
{
    /// <summary>
    /// FriendsListPage.xaml 的交互逻辑
    /// </summary>
    public partial class ContactPage : Page
    {
        public ContactPage()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 好友列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StackPanel_MouseUp(object sender, MouseButtonEventArgs e)
        {
            GuiCache guic = GuiCache.Instance;
            MyFriendsPage mfp = (MyFriendsPage)guic.getGui("MyFriendsPage");
            MainWindow mw = (MainWindow)guic.getGui("MainWindow");
            if(mfp != null)
            {
                mw.RightFrame.Content = mfp;
                // 刷新列表
                MessageCO messageCO = new MessageCO();
                messageCO.type = (int)RequestEnum.request.GetFriends;
                Radar.Instance.sendData(messageCO);
            }
            else
            {
                mfp = new MyFriendsPage();
                guic.setGui("MyFriendsPage", mfp);
                mw.RightFrame.Content = mfp;
                // 初始化拿数据
                MessageCO messageCO = new MessageCO();
                messageCO.type = (int)RequestEnum.request.GetFriends;
                Radar.Instance.sendData(messageCO);
            }
        }

        private void ShowMyGroupsPage(object sender, MouseButtonEventArgs e)
        {
            GuiCache guic = GuiCache.Instance;
            MyGroupsPage mgp = (MyGroupsPage)guic.getGui("MyGroupsPage");
            MainWindow mw = (MainWindow)guic.getGui("MainWindow");
            if (mgp != null)
            {
                mw.RightFrame.Content = mgp;
                // 刷新列表群组
                MessageCO messageCO = new MessageCO();
                messageCO.type = (int)RequestEnum.request.GetGroupList;
                Radar.Instance.sendData(messageCO);
            }
            else
            {
                mgp = new MyGroupsPage();
                guic.setGui("MyGroupsPage", mgp);
                mw.RightFrame.Content = mgp;
                // 初始化拿数据
                MessageCO messageCO = new MessageCO();
                messageCO.type = (int)RequestEnum.request.GetGroupList;
                Radar.Instance.sendData(messageCO);
            }
        }
    }
}
